package org.gradle.springboot.services;


import java.util.List;
import java.util.Map;

import org.gradle.springboot.bean.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

@Service
public class UserService {
	
	@Autowired
	private JdbcTemplate jdbcTemplate;
	
	public Object getAllUsers() {
		String sql = "select * from t_user u order by u.name";
		List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
		return list;
	}
	
	public Student loadStudent(String id) {
		List<Map<String, Object>> list = jdbcTemplate.queryForList("select * from t_user u where u.id = ?", new Object[]{id});
		Student s = new Student();
		
		for (Map<String, Object> map : list) {
			s.setName(map.get("name").toString());
			s.setId(map.get("id").toString());
		}
		return s;
	}

}
